﻿using System;
using Fly.Data;
using FlyWebFrame.Model;

namespace FlyWebFrame.Action.admin
{
    public class account : baseaction
    {
        public dynamic view;

        public override void Treat()
        {
            contentleft = "/html/admin/account.htm";
            page_title += " - Quản lý tài khoản";
            admin_script = "$('#ad_account').addClass('active');";
            
            Admin acc = new Admin();
            view = acc.Get().Data;
            if (view != null)
            {
                for (int i = 0; i < view.Length; i++)
                {
                    if (view[i].Name == login_name) // cannot delete myself
                    {
                        admin_script += "$('#delete_" + view[i].Id + "').remove();";
                    }
                    if (login_name != "admin")
                    {
                        admin_script += "$('#delete_" + view[i].Id + "').remove();"; // can not delete anyone
                        admin_script += "$('#btn_addacc').remove();";
                        if(login_name != view[i].Name)
                            admin_script += "$('#edit_" + view[i].Id + "').remove();"; // can not edit another account if not admin
                    }
                }
            }
        }
    }
}